package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PrizeInfo;
import com.ruoyi.system.service.IPrizeInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖品Controller
 * 
 * @author ruoyi
 * @date 2021-04-07
 */
@RestController
@RequestMapping("/system/prizeinfo")
public class PrizeInfoController extends BaseController
{
    @Autowired
    private IPrizeInfoService prizeInfoService;

    /**
     * 查询奖品列表
     */
    @PreAuthorize("@ss.hasPermi('system:prizeinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrizeInfo prizeInfo)
    {
        List<PrizeInfo> list = prizeInfoService.selectPrizeInfoList(prizeInfo);
        return getDataTable(list);
    }

    /**
     * 导出奖品列表
     */
    @PreAuthorize("@ss.hasPermi('system:prizeinfo:export')")
    @Log(title = "奖品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrizeInfo prizeInfo)
    {
        List<PrizeInfo> list = prizeInfoService.selectPrizeInfoList(prizeInfo);
        ExcelUtil<PrizeInfo> util = new ExcelUtil<PrizeInfo>(PrizeInfo.class);
        return util.exportExcel(list, "prizeinfo");
    }

    /**
     * 获取奖品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:prizeinfo:query')")
    @GetMapping
    public AjaxResult getInfo(PrizeInfo prizeInfo)
    {
        return AjaxResult.success(prizeInfoService.selectPrizeInfoById(prizeInfo));
    }

    /**
     * 新增奖品
     */
    @PreAuthorize("@ss.hasPermi('system:prizeinfo:add')")
    @Log(title = "奖品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrizeInfo prizeInfo)
    {
        return toAjax(prizeInfoService.insertPrizeInfo(prizeInfo));
    }

    /**
     * 修改奖品
     */
    @PreAuthorize("@ss.hasPermi('system:prizeinfo:edit')")
    @Log(title = "奖品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrizeInfo prizeInfo)
    {
        return toAjax(prizeInfoService.updatePrizeInfo(prizeInfo));
    }

    /**
     * 删除奖品
     */
    @PreAuthorize("@ss.hasPermi('system:prizeinfo:remove')")
    @Log(title = "奖品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prizeIds}")
    public AjaxResult remove(@PathVariable String[] prizeIds)
    {
        return toAjax(prizeInfoService.deletePrizeInfoByIds(prizeIds));
    }
}
